﻿using Common.ORM.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FreeRedis;
using sixgod.Common.Helper;
using sixgod.Model.Attribute;
using sixgod.Model.User;
using SqlSugar;

namespace sixgod.Service.User.Implementation
{
    [Di(typeof(IJobService))]
    public class JobService:Repository<Job>, IJobService
    {
        public JobService(RedisClient redisClient, ISqlSugarClient db) : base(redisClient, db)
        {

        }

        /// <summary>
        /// 获取用户直接上级
        /// </summary>
        /// <param name="jobId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task<Model.User.User> GetJobLeader(string jobId = null)
        {
            jobId ??= UserContext.Current.UserToken.JobId;

            var job = await GetByIdAsync(jobId);

            return await Context.Queryable<Model.User.User>().Where(r=>r.JobId == job.ParentCode).FirstAsync();
        }
    }
}
